package com.jwb.pub.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jwb.pub.dao.BaseDAO;
import com.jwb.pub.service.ScheduleService;
import com.jwb.util.MainController;
import com.jwb.util.ToolsUtil;
@Slf4j
@Controller
@RequestMapping("/pub/schedule")
public class ScheduleController  extends MainController {

	@Autowired
	private BaseDAO baseDAO;
	
	@Autowired
	private ScheduleService scheduleService;
	
	/** 
	 * http://127.0.0.1:8080//ssm/pub/schedule/scheduleSave
	 * {}
	 * name 任务名  不为空
	 * url 前台写死 http://12.1.1.43:8001//kpnmrb/test/autonkhd.mvc
	 * req_data "start_date=&end_date="
	 * @param req
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/scheduleSave")    
    @ResponseBody
    public String  messageSave(HttpServletRequest req,HttpServletResponse response) throws Exception {
    	JSONObject jsobject = new JSONObject();  
        String jsonStr = req.getParameter("jsonStr") == null ? "{}" : req.getParameter("jsonStr");
    	JSONObject jsdata = new JSONObject();
    	try {

			jsdata=JSONObject.parseObject(jsonStr);		
			String id=ToolsUtil.get32bituuid();
			jsdata.put("id", id);
			jsdata.put("sts", "A");
    		jsobject = scheduleService.scheduleAdd(jsdata);
			scheduleService.scheduleExcute(jsdata);		
			jsobject.put("id", id);
    	
		} catch (Exception e) {
			e.printStackTrace();
			jsobject.put("respCode", "-3");
			jsobject.put("respDesc", "字符串格式有误");	

		}
    	log.info("scheduleSave():" + jsobject.toString());
    	return jsobject.toString();	
    }
	
	@RequestMapping("/testUrl")
	@ResponseBody
	public String testUrl(HttpServletRequest req,HttpServletResponse res){
		JSONObject result = new JSONObject();		
		String start_date="";
		String end_date="";		
		start_date = req.getParameter("start_date");
		end_date = req.getParameter("end_date");		
 	    result.put("respCode", "0");	
 	    System.out.println(start_date+"----"+end_date);
		return result.toString();
	}
}
